from flask import Flask
from flask_cors import CORS
from utils.jwt_auth import jwt_authentication
from models import db
from views.users.user import user_bp
from views.users.news import news_bp
from views.users.channel import channel_bp
from views.users.commton import comment_bp


def create_flask_app(config):
    app = Flask(__name__)      #初始化flask
    CORS(app,resources=r'/*')     #配置跨域
    app.config.from_object(config)  #读取配置文件对象
    db.init_app(app)    #初始化数据库

    # 使用请求钩子  验证token
    app.before_request(jwt_authentication)

    app.register_blueprint(user_bp)   #注册用户蓝图
    app.register_blueprint(news_bp)
    app.register_blueprint(comment_bp)
    app.register_blueprint(channel_bp)  # 注册频道蓝图

    return app